﻿using System;
using System.Linq;
using System.ServiceModel.DomainServices.Client;
using GSSoftSL.Web.Models;
using GalaSoft.MvvmLight;

namespace GSSoftSL.ViewModel
{
    public class KhoaHocChiTietViewModel : ViewModelBase
    {
        private KhoaHocChiTiet _model;
        public KhoaHocChiTiet Model 
        { 
            get { return _model; } 
        }

        private LopChiTietProxy _proxy;
        public LopChiTietProxy Proxy
        {
            get { return _proxy; }
            set
            {
                _proxy = value;
                RaisePropertyChanged("Proxy");
            }
        }

        //private Phong[] _allPhong = null;

        private Phong[] _phongs;
        public Phong[] Phongs
        {
            get { return _phongs; }
            set
            {
                _phongs = value;
                RaisePropertyChanged("Phongs");
            }
        }

        private CaHoc[] _caHocs;
        public CaHoc[] CaHocs
        {
            get { return _caHocs; }
            set
            {
                _caHocs = value;
                RaisePropertyChanged("CaHocs");
            }
        }

        /*private int?[] _tangs;
        public int?[] Tangs
        {
            get { return _tangs; }
            set
            {
                _tangs = value;
                RaisePropertyChanged("Tangs");
            }
        }

        private int _tang;
        public int Tang
        {
            get { return _tang; }
            set
            {
                if (_tang == value)
                    return;
                _tang = value;
                RaisePropertyChanged("Tang");
                Phongs = _allPhong.Where(n => n.Tang == _tang).ToArray();
            }
        }*/

        public KhoaHocChiTietViewModel(KhoaHocChiTiet model, Phong[] phongs, CaHoc[] caHocs)
        {
            _model = model;
            Phongs = phongs;
            CaHocs = caHocs;
            /*Tangs = phongs.Where(n => n != null).Select(n => n.Tang).ToArray();
            if (Tangs.Length > 0)
                Tang = Tangs[0].Value;*/
            Proxy = new LopChiTietProxy()
            {
                NgayTrongTuan = _model.NgayTrongTuan,
                BuoiHoc = _model.BuoiHoc,
                CaHoc = _model.CaHoc,
                Phong = _model.Phong
            };
        }

        public void CopyValue()
        {
            _model.NgayTrongTuan = _proxy.NgayTrongTuan;
            _model.BuoiHoc = _proxy.BuoiHoc;
            _model.CaHoc = _proxy.CaHoc;
            _model.Phong = _proxy.Phong;
        }

        private DateTime GetTime(DateTime time)
        {
            return new DateTime(2000, 1, 1, time.Hour, time.Minute, time.Second);
        }
    }

    public class LopChiTietProxy : Entity
    {
        private int _ngayTrongTuan;
        public int NgayTrongTuan
        {
            get { return _ngayTrongTuan; }
            set
            {
                _ngayTrongTuan = value;
                RaisePropertyChanged("NgayTrongTuan");
            }
        }

        private int _buoiHoc;
        public int BuoiHoc
        {
            get { return _buoiHoc; }
            set
            {
                _buoiHoc = value;
                RaisePropertyChanged("BuoiHoc");
            }
        }

        private CaHoc _caHoc;
        public CaHoc CaHoc
        {
            get { return _caHoc; }
            set
            {
                _caHoc = value;
                RaisePropertyChanged("CaHoc");
            }
        }

        private Phong _phong;
        public Phong Phong
        {
            get { return _phong; }
            set
            {
                _phong = value;
                RaisePropertyChanged("Phong");
            }
        }
    }
}